package com.yungu.swift.admin.route.finance;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.admin.utils.ExcelUtil;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.system.finance.model.param.AdminInviteRewardPageParam;
import com.yungu.swift.system.finance.model.vo.FinanceDriverRewardVo;
import com.yungu.swift.system.finance.service.FinanceInviteRewardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author : cuixiuyin
 * @date : 2019/8/9
 */
@RestController
@RequestMapping("/admin/v1/finance/inviteReward")
@Api(value = "【财务管理】", tags = "邀请奖励")
public class InviteRewardAdmin {

    @Reference
    private FinanceInviteRewardService financeInviteRewardService;

    @RequestMapping(value = "/queryPage", method = RequestMethod.POST)
    @ApiOperation(value = "司机奖励情况分页", httpMethod = "POST")
    public ResponseData<PageVo<FinanceDriverRewardVo>> queryPage(@RequestBody AdminInviteRewardPageParam rewardPageParam) {
        return financeInviteRewardService.driverRewardPage(rewardPageParam);
    }


    @RequestMapping(value = "/export", method = RequestMethod.POST)
    @ApiOperation(value = "司机奖励情况导出", httpMethod = "POST")
    public void export(@RequestBody AdminInviteRewardPageParam rewardPageParam, HttpServletResponse response) {
        ResponseData<List<FinanceDriverRewardVo>> responseData = financeInviteRewardService.driverRewardExport(rewardPageParam);
        if (responseData.isSuccess() && CollectionUtils.isNotEmpty(responseData.getData())) {
            List<FinanceDriverRewardVo> list = responseData.getData();
            Map<Object, Object>[] dictionaryMapArray = new Map[4];

            ExcelUtil.export(response, "司机奖励情况", list, 4,
                    new String[]{"领取时间", "金额", "司机联系电话", "司机姓名"},
                    new String[]{"createOn", "amount", "driverInviterName", "driverMobile"}, dictionaryMapArray);
        }
    }

}
